class Exercise

    def initialize(fullname)
        @fullname=fullname
    end

    def rearrange
        fullname_array = @fullname.split(' ')
        firstname = fullname_array[1]
        lastname = /(\w+)/.match("#{fullname_array[0]}")[1]
        if fullname_array.length > 2
            middlename = /(^\w)/.match("#{fullname_array[2]}")[1]
            "#{firstname} #{middlename}. #{lastname}"
        else "#{firstname} #{lastname}"
        end
    end
end

